#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
bool is_prime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i*i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

void find_prime(string input) {
    unordered_map<string, int> word_to_num = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    vector<string> words;
    string word;
    for (char c : input) {
        if (c == ' ') {
            words.push_back(word);
            word = "";
        } else {
            word += c;
        }
    }
    words.push_back(word);

    if (words.size() != 3) {
        cout << "Wrong input" << endl;
        return;
    }

    int num = stoi(to_string(word_to_num[words[0]]) + to_string(word_to_num[words[1]]) + to_string(word_to_num[words[2]));

    if (100 <= num && num <= 999) {
        int lower = num;
        int upper = num;
        while (true) {
            if (is_prime(lower)) {
                cout << lower << endl;
                break;
            }
            if (is_prime(upper)) {
                cout << upper << endl;
                break;
            }
            lower--;
            upper++;
        }
    } else {
        cout << "Wrong input" << endl;
    }
}

int main() {
    string input;
    cout << "Enter three words: ";
    getline(cin, input);
    find_prime(input);

    return 0;
}